import { applyMiddleware, compose } from 'redux';
import { configureStore } from '@reduxjs/toolkit';

import reucer from './reducer';
import thunk from 'redux-thunk';


const composeEnhancers = typeof window === 'object' &&
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ?
  window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({}) : compose;

const enhancers = composeEnhancers(applyMiddleware(thunk));

/**
 * 将数据操作进行汇总，通过唯一区分，
 * 1. 避免不同组件间数据干扰
 * 2. 组件间各自委会自身 store, 降低维护成本
 */
const store = configureStore({
  reducer: reucer,
  enhancers: enhancers,
})

export default store;